package com.liu.demo.service;

import com.liu.demo.exception.REnum;
import com.liu.demo.exception.RException;
import com.liu.demo.pojo.User;
import com.liu.demo.prository.UserPrository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserPrository userPrository;

    public User login(Integer username,String password) throws Exception{
        List<User> users = userPrository.findByUsernameAndPassword(username,password);

        if(users.size() > 0){
            return users.get(0);
        }else{
            throw new RException(REnum.LOGIN_ERR);
        }
    }
}
